package com.module.dialog;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.module.dialog.utils.ProgressType;

/**
 * 进度条对话框
 * Created by dell on 2018/7/5
 */

public class ProgressDialog extends BaseBuilder implements View.OnClickListener {
    TextView textView;
    ProgressBar progressBar, progressBar2;
    ProgressParam mProgressParam;

    public ProgressDialog(Context context) {
        super(context);
    }

    /**
     * 初始化控件
     */
    @Override
    public void initContentView(){
        mProgressParam = new ProgressParam();
        View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_progress, null);
        textView = view.findViewById(R.id.textView);
        progressBar = view.findViewById(R.id.progressBar);
        progressBar2 = view.findViewById(R.id.progressBar2);
        setContentView(view);
    }

    @Override
    public BaseBuilder getBuilder() {
        return this;
    }

    @Override
    protected void connectView() {
        if(mProgressParam.type == ProgressType.LoadingCircle){
            progressBar2.setVisibility(View.GONE);
        }else if(mProgressParam.type == ProgressType.LoadingHorizontal){
            progressBar.setVisibility(View.GONE);
            textView.setVisibility(View.GONE);
        }
    }

    public ProgressDialog setStyle(ProgressType type){
        mProgressParam.type = type;
        return this;
    }

    public ProgressDialog setProgress(int progress){
        mProgressParam.progress = progress;
        return this;
    }

    public ProgressDialog setMax(int max){
        return this;
    }

    public ProgressDialog setCallBack(DialogCallBack listener) {
        mProgressParam.callBackListener = listener;
        return this;
    }

    /**
     * 重写按钮点击事件
     */
    @Override
    public void onClick(View v) {
        super.onClick(v);
        if(mProgressParam.callBackListener != null){
            int tag = Integer.parseInt(v.getTag().toString());
            mProgressParam.callBackListener.callback(tag);
        }
    }

    public class ProgressParam {
        public int progress;
        public ProgressType type = ProgressType.LoadingCircle;
        public DialogCallBack callBackListener;

    }

    public interface DialogCallBack {
        void callback(int which);
    }

}